# -*- coding: utf-8 -*-   
#bilibili win端客户端 用来下罗小黑
#自动根据下载信息改名
#自动剪切/复制到指定文件夹下

#参考：http://www.chenxm.cc/article/220.html
#     https://www.cnblogs.com/orangeJJJ/p/10109232.html
#     https://blog.csdn.net/liulin1207/article/details/107002722/
#     https://blog.csdn.net/longshaonihaoa/article/details/105679517
#     https://blog.csdn.net/wowocpp/article/details/79460407

import os
import configparser
import shutil

def copyfile(srcfile,dstpath):
    if not os.path.isfile(srcfile):
        print("%s not exist!"%(srcfile))
    else:
        fpath,fname=os.path.split(srcfile) #分离文件名和路径
        if not os.path.exists(dstpath):    #创建路径
            os.makedirs(dstpath)
        shutil.copy(srcfile,dstpath+fname)
        print("copy %s"%(srcfile))

root="C:/Users/白白白/AppData/Local/Packages/36699Atelier39.forWin10_pke1vz55rvc1r/LocalCache/BilibiliDownload/ss1733"
dst_dir=root+"/copy/"
dirlist=os.listdir(root)
for fileDir in dirlist:
    if fileDir.find(".")==-1:
        dir=root+"/"+fileDir
        cf=configparser.ConfigParser()
        cf.read(dir+"/"+"desktop.ini")
        fileTruename=cf.get(".ShellClassInfo","infoTip")
        #复制
        dirlist2=os.listdir(dir+"/1")
        for filename in dirlist2:
            if filename.find("mp4")>=0:
                copyfile(dir+"/1/"+filename,dst_dir)
                os.rename(dst_dir+filename,dst_dir+fileTruename+".mp4")
                print("rename %s --> %s"%(filename,fileTruename))






